package ces.org.course.cuixiaowei.api.entity; /**
 * <p>Copyright:Copyright(c) 2019</p>
 * <p>Company:Professional</p>
 * <p>Package:ces.org.course.api.entity</p>
 * <p>File:Dictionary.java</p>
 * <p>类更新历史信息</p>
 * @todo chanlong(陈龙) 创建于 May 20, 2019 1:31:04 PM
 */

import ces.org.course.cuixiaowei.ext.xml.Dictionary;
import cn.hutool.json.JSONUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * <p>描述: </p>
 * <p>Company: Professional</p>
 * @author chanlong(陈龙)
 * @date May 20, 2019 1:31:04 PM
 * @version 1.0.2019
 */
@Slf4j
@Data @SuppressWarnings("serial")
@EqualsAndHashCode(callSuper = false)
public class DictionaryEntity extends LinkedHashMap<String, Map<String, Object>> implements Serializable {

	public static DictionaryEntity of() {
		return new DictionaryEntity();
	}
	
	public DictionaryEntity create(final Dictionary dictionary) {
		dictionary.getDict().forEach(dict -> {
			this.setKey(dict.getKey());
			this.setName(dict.getName());
			dict.getCode().forEach(code -> {
				if (!this.containsKey(key)) this.put(key, new LinkedHashMap<>());
				this.get(key).put(code.getText(), code.getValue());
			});
		});
		
		log.info("The Dictionary is loaded: {}", JSONUtil.toJsonPrettyStr(this));
		return this;
	}
	
	private DictionaryEntity() {

	}
	
	private String key;
	private String name;
	private Map<String, Object> codes;
	public static String CACHE_KEY = "dictionary";
	
}
